<template>
  <rx-dialog @handOk="handTrans" @cancel="cancel" order="bottom" >
    <rx-layout>
      <div slot="center">
        <a-form-model ref="form" :model="form" :rules="rules">
          <a-row>
            <a-col :span="24">
              <a-form-model-item :labelCol="labelCol1" :wrapperCol="wrapperCol1" :label="i18n('flowPage.taskName','任务名称')">
                {{form.subject}}
              </a-form-model-item>
            </a-col>
          </a-row>
          <a-row>
            <a-col :span="24">
              <a-form-model-item :labelCol="labelCol1" :wrapperCol="wrapperCol1" :label="i18n('transferPage.transferor','转办人')"  prop="toUser">
                  <rx-user-component v-model="form.toUser" :isAccount="false" :single="true"></rx-user-component>
              </a-form-model-item>
            </a-col>
          </a-row>
          <a-row>
            <a-col :span="24">
              <a-form-model-item :labelCol="labelCol1" :wrapperCol="wrapperCol1" :label="i18n('taskCheck.opinion','意见')" prop="opinion">
                <a-textarea v-model="form.opinion" style="width: 100%"/>
              </a-form-model-item>
            </a-col>
          </a-row>
        </a-form-model>
      </div>
    </rx-layout>
  </rx-dialog>
</template>
<script>

  import BpmPublicApi from '@/api/bpm/core/BpmPublicApi'
  import {BaseFormModel, RxDialog,RxUserComponent,Dialog,Util} from '@lowcode/jpaas-common-lib';
  import BpmtaskApi from "@/api/bpm/core/bpmTask";

  export default {
    name: 'BpmTaskTransferEdit',
    props:{
        subject:String,
        taskId:String,
        layerid: String,
        lydata: Object,
        destroy:Function
    },
    mixins:[BaseFormModel],
    components: {
      RxDialog,RxUserComponent
    },
    data(){
      return {
        rules: {
            toUser:[{ required: true, message: this.i18n('transferPage.transferor','转办人','select'), trigger: 'change' }]
        },
        form:{
            opinion:"",
            toUser:[],
            msgTypes:[]
        }
      }
    },
    created(){
      this.init();
    },
    methods: {
      i18n(name,text,key){
          return this.$ti18(name,text,"bpmTask",key);
      },
      init(){
          this.form.subject=this.subject;
          this.form.taskId=this.taskId;
      },
      handTrans(e){
          this.$refs.form.validate(valid=>{
              if(!valid){
                  e.loading=false;
                  return;
              }
              this.form.msgType=this.form.msgTypes.join(",");
              var _set = this;
              this.$confirm({
                  title: _set.i18n('transferPage.confirmTransfer','确认转办任务吗?'),
                  okText: this.$ti18('rxForm.ackBtn','确认'),
                  cancelText: this.$ti18('rxForm.cancelBtn','取消'),
                  zIndex:9999,
                  onOk() {
                      BpmtaskApi.transTask(_set.form).then(res=>{
                          e.loading=false;
                          Util.closeWindow(_set,"ok")
                      })
                  },
                  onCancel() {
                      e.loading=false;
                  }
              },);
          });
      }
    }
  }
</script>
